#ifndef _REGISTERPLOT_H_
#define _REGISTERPLOT_H_

#include <qwt_array.h>
#include <qwt_plot.h>
#include <qwt_scale_draw.h>

class QwtPlotCurve;
class QwtLegend;

class CurveData
{
    // A container class for growing data
public:

    CurveData(int maxSize);

    void append(double *x, double *y, int count);

    int count() const;
    int size() const;
    const double *x() const;
    const double *y() const;

private:
    int d_count;
    int d_maxsize;
    QwtArray<double> d_x;
    QwtArray<double> d_y;
};

class Destructor : public QObject
{
    Q_OBJECT

public:
    Destructor(QwtPlotCurve *item, CurveData *data);
    ~Destructor();

private:
    QwtPlotCurve *m_item;
    CurveData *m_data;
};

class TimeScaleDraw: public QwtScaleDraw
{
public:
    TimeScaleDraw();
    virtual QwtText label(double v) const;
};

class RegisterPlot : public QwtPlot
{
    Q_OBJECT

public:
    RegisterPlot(int curveSize, QWidget *parent = NULL);
    virtual ~RegisterPlot();

    void appendData(double x, double y, int curve);
    void appendData(double *x, double *y, int size, int curve);

    void removeData();
    void addCurve(const char * name, QColor color);

    int count();

public slots:
    void removeCurve(QwtPlotItem* item);

private:
    void init();

    QList<CurveData*> *d_data;
    QList<QwtPlotCurve*> *d_curve;
    QwtLegend *d_legend;
    TimeScaleDraw *d_scale;
    int m_maxCurveSize;

};

#endif // _REGISTERPLOT_H_
